# Multiple Linear Regression

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
from sklearn import preprocessing
from sklearn.preprocessing import PolynomialFeatures

from sklearn.cluster import KMeans

import joblib


def train(dataPath, modelSavePath):
    print('\nclustering: ', dataPath)

    # Importing the dataset
    dataset = pd.read_csv(dataPath)
    print('dataset: ')
    print(dataset)
    X = dataset.iloc[:, :-1]
    y = dataset.iloc[:, dataset.shape[1] - 1]


    km = KMeans(n_clusters=3).fit(y.values.reshape(-1,1))
    # 标签结果
    rs_labels = km.labels_
    # 每个类别的中心点
    rs_center_ids = km.cluster_centers_

    # 描绘各个点
    plt.scatter(y.index, y.values, c=rs_labels, alpha=0.5)
    # 描绘质心
    # plt.scatter([0 for _ in range(km.n_clusters)], rs_center_ids[:, 0], c='red')

    plt.show()
    # print(' ')

    dataset['category']=rs_labels
    print(dataset)

    dataset.to_csv(dataPath, index=False, sep=',')



if __name__ == '__main__':
    train('../../data/ingotRate.csv','./ingotRatePrediction.pkl')
    # train('../../data/yieldRate.csv','./yieldRatePrediction.pkl')

